package com.dbsop.domain.params;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ESPage <T> implements Serializable {

    private static final long serialVersionUID = 2769641670456027982L;
    /**
     * 当前页码
     */
    private int currentNumber=1;

    /**
     * 分页数量
     */
    private int  currentSize=10;

    /**
     * 实体内容
     */
    private List<T> content = new ArrayList<T>();

    /**
     * 总页数
     */
    private long totalPage = 0;

    /**
     * 总数量
     */
    private long totalSize = 0;

    public ESPage() {
    }

    public ESPage(int currentNumber, int currentSize) {
        this.currentNumber = currentNumber;
        this.currentSize = currentSize;
        if (this.currentNumber<=0)this.currentNumber = 1;
        if (this.currentSize<=0)this.currentSize = 10;
    }

    public Integer getFrom() {
        return (currentNumber-1)*currentSize;
    }

    public Integer getCurrentNumber() {
        return currentNumber;
    }

    public void setCurrentNumber(int currentNumber) {
        if (currentNumber<=0)return;
        this.currentNumber = currentNumber+1;
    }

    public int getCurrentSize() {
        return currentSize;
    }

    public void setCurrentSize(int currentSize) {
        if (currentSize<=1)return;
        this.currentSize = currentSize;
    }

    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        if (content == null)return;
        this.content = content;
    }

    public long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(long totalPage) {
        this.totalPage = totalPage;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        if (totalSize<=0)return;
        totalPage =  totalSize/currentSize + (totalSize%currentSize>0?1:0);
        this.totalSize = totalSize;
    }
}
